\section{Implementation}\label{sec_implementation}

Due to the different parts of the system which are required to parts of the system, different languages and techniques were required.  The the project consists of two types of programming language a web development and a general purpose language.  The web development language is required for the creation of the KAPTCHA system as well as the image labelling game.  The general purpose language is required for the automated collection of images. 


\subsection{Possible Server side Implementation Tools}\label{subsec_server_impl_tools}

The implementation language of the project is each with there own merits and drawbacks.
\subsubsection{Languages}\label{subsubsec_languages}
\begin{itemize}
\item Coldfusion - The language is widely used within the University for web development in the, this language would have been chosen if the applications were to be maintained by another developer, this is due to the high level of expertise the university has in this implementation language.
\item Python - The language has found increasing use in web applications especially with the backing of Google and its use in the implementation of Google Apps Engine.  Although there is much Python experience in the University, it is not commonly used for web development.
\item Ruby - Relatively new programming language which is often use with the Rails framework, as such the combination is usually refereed to as Ruby on Rails see section \ref{subsubsec_serversideframeworks}.
\item Java - Provide web applications through the use of Java Server Pages or the compiled version Java Servlets.  Although there is much experience in the university in managing large Java based programs, Java is best used when the back-end is also implemented in Java.
\item PHP - One of the most common web development languages with many books and examples available.  There is also much expertise in the university if the project should be further developed.
\end{itemize}

Due to the research conducted I decided that PHP was the correct implementation language for the creation of the project.  This is due to the abundance of resources tutorials, books and lecture notes which will aided in the creation of the project.


\subsubsection{General Purpose Language}

\subsection{Coding Standards}\label{subsec_codingstandards}
The coding standards of of my project evolved as my experience with developing large web applications grew.  Code re-factoring was an iterative activity which occurred throughout the implementation of the project. As such the project moved from an imperitive approach to an object orientated structure.



\subsection{Database Implementation} 
Two types of relational databases were available for the project.  MySQL and Oracle were both available within the university.  MySQL was chosen due to the tools avialable most notably phpMyAdmin.  This is a web-based graphical frontend which provides more functionality than its Oracle counterpart. The key feature of phpMyAdmin was its ability to export data in many formats, including SQL in Oracle syntax.  This was key, at this point in the project
as the implementation was conducted using servers which were only accessible from within the university(bantayan).  The university technical staff were unwilling to provide a PHP server which could be accessed from outside of the university due to the potential security problems with carefully crafted input, which was not expected by the programmer.  This generally is in the form of an SQL injection attack in which SQL commands are inserted into where the programmer expects only data to be inserted.  Due to this it was unclear what tools would be available on an external server when one became available.  It was not possible to create an SSH (Secure SHell) tunnel through to the university server as the technical staff in-charge of the RNIB systems would not allow the installation of appropriate software, such as PuTTY \footnote{\url{http://www.chiark.greenend.org.uk/~sgtatham/putty/}} on the Windows XP desktops which the experiments participants use.  An external server was purchased, which ran MySQL as the database. 



\begin{figure}[h]\label{fig_erdiagram}
\centering
 \includegraphics[width=150mm]{erdiagram.eps}
\caption{Organisation of the database holding information for the labelling game}
\end{figure}

Figure \ref{fig_erdiagram} details the design of the database, which was implemented to provide storage for the images, as well as their assignment of labels, which have been provided by users.


\subsection{Image Collector}\label{subsect_imagecollectlang}
The decision on which language to implement the image collection in the system was dependant on three factors:

\begin{itemize}
\item the first was that the code should be maintainable, portable and efficient.  
\item a high level of efficiency would be required for further projects which require large numbers of images.
\item to be adaptable to new requirements and new projects.
\end{itemize}

MySQL has an API which would allow the C code to access the database, which is highly likely that this will be more efficient than other languages connector API.  This is due to C being MySQL's native language. It not a popular language due to its low-level nature and will probably, few people are likely to be  willing to maintain the code when simpler languages are available.  The API for providing MySQL connectivity to C programs is far more complex than that of Java.  This would increase the time for the code to be adapted to modifications in any further work on this project or for future projects which require large numbers of images and would reduce the likelihood that the code will be reused.  Therefore, to provide a high level of  maintainability and portability, Java was chosen as the implementation language.  Java provides a simple API for accessing databases through the use of JDBC. However, at the implementation stage of the image collector, it was highly probable that some requirements would change. This would require the database to be modified along with embedded SQL, which would be affected by the changes to the database.  To prevent significant scheduling problems caused by changing requirements, a more flexible solution was required.  To solve this problem Hibernate\footnote{\url{http://www.hibernate.org}} was employed.  This is an object-relational mapping (ORM) framework for Java which significantly reduced the implementation time and would have made it very efficient and easy to make large scale changes to the database had it been necessary.

\subsection{Image Manipulation}\label{subsect_imagemanip}

The system required two sizes of images: a large image for the labelling game and a slightly smaller size for the KAPTCHA.  To provide an automated process for achieving this, a simple BASH script was implemented.  This required the use of the command line image manipulation Library, particularly the convert command, which provided the functionality for resizing the images.  Although not portable, the script would require very little work to make it available to other operating systems. The ImageMagick library is also available for the most common operating systems  Mac OS X and  Windows. This is a feature which would be high desirable as part of the image collection API.


\begin{figure}[h]\label{fig_automatedimagecollection}
\centering
 \includegraphics[width=150mm]{imagecollection.eps}
\caption{Architecture of the automated image collection sub-system}
\end{figure}



% Really should add
\subsubsection{Client Side Scripting toolkits}\label{subsubsec_clientsideframeworks}
The client side scripting of the project was focused on the implementation of the game. 


\subsubsection{Server Side Scripting Frameworks}\label{subsubsec_serversideframeworks}
The use of the a framework was highly dependant on the language used.  A framework would have provided many advantages such the implementation of common tasks and provide templates for the common patterns in web development.  Research into the frameworks provided 
\begin{itemize}
\item Rails - Most commonly associated with the Ruby Language, Rails provides a MVC(Model View Controller) framework.  The aim of Rails is to allow the programmer to focus on the unconventional aspects of a project rather than repetitive tasks which are common to all projects.
\item PEAR -  PHP Extension and Application Repository which contains a library of commonly used PHP functions.
\item Django - Provides similar functionality to the Rails framework for the Python language.
\end{itemize}

Due to the prevalence of experience and availability of tools PHP is the prefered implementation language.  The implementation of the project would have benefited from the of PEAR. However, it was not available from the university machines.  Although an external web server was acquired, much of the implementation had been completed before this became available.  
